package com.quan.mall.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quan.commons.core.biz.support.MyBaseServiceImpl;
import com.quan.commons.core.utils.PageUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.quan.mall.commons.vo.OmsOrderSettingVo;
import com.quan.mall.entity.OmsOrderSetting;
import com.quan.mall.mapper.OmsOrderSettingMapper;
import com.quan.mall.service.OmsOrderSettingService;


@Slf4j
@Service
public class OmsOrderSettingServiceImpl extends MyBaseServiceImpl<OmsOrderSettingMapper, OmsOrderSetting> implements OmsOrderSettingService {

    @Autowired
	private OmsOrderSettingMapper mapper;

	@Override
    public List<OmsOrderSettingVo> queryList(PageUtils pageUtils, OmsOrderSettingVo vo) {
        QueryWrapper<OmsOrderSetting> queryWrapper = new QueryWrapper<OmsOrderSetting>(vo);

        List<OmsOrderSetting> list = super.list(pageUtils, queryWrapper);
        List<OmsOrderSettingVo> collect = list.stream().map(item -> {
            OmsOrderSettingVo bean = new OmsOrderSettingVo();
            BeanUtils.copyProperties(item, bean);
            return bean;
        }).collect(Collectors.toList());

        return collect;
    }

    @Override
    public PageUtils queryPage(PageUtils pageUtils, OmsOrderSettingVo vo) {
        QueryWrapper<OmsOrderSetting> queryWrapper = new QueryWrapper<OmsOrderSetting>(vo);

        if(StringUtils.isNotBlank(vo.getKeyword())) {
            queryWrapper.and(w -> {
                w.like("name", vo.getKeyword());
            });
        }

        final IPage<OmsOrderSetting> page = super.selectPage(pageUtils, queryWrapper);

        PageUtils ps = new PageUtils(page);

        final List<OmsOrderSetting> records = page.getRecords();

        final List<OmsOrderSetting> collect = records.stream().map((item) -> {
            OmsOrderSettingVo bean = new OmsOrderSettingVo();
            BeanUtils.copyProperties(item, bean);
            return bean;
        }).collect(Collectors.toList());

        ps.setRecords(collect);
        return ps;
    }
}